<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="wz">123</div>
    <script>
      getWeatherFn = async () => {
        try {
          const res = await fetch('https://restapi.amap.com/v3/ip?key=高德key')
          const position = await res.json() // 如果数据是JSON格式
          const response = await fetch(`https://restapi.amap.com/v3/weather/weatherInfo?key=高德key&extensions=base&city=${position.city}`)
          const weather = await response.json()
          console.log('当前位置', position)
          console.log('当前天气', weather)
        } catch (error) {
          console.error(error)
        }
      }

      getWeatherFn()
    </script>

    <!-- 高德定位 -->
    <!-- <script>
      var xhr = new XMLHttpRequest()
      xhr.onreadystatechange = () => {
        if (xhr.readyState == 4) {
          console.log(JSON.parse(xhr.responseText))
        }
      }
      xhr.open('get', 'https://restapi.amap.com/v3/ip?key=高德key', true)
      xhr.send()
    </script> -->

    <!-- 高德天气查询 -->
    <!-- <script>
      var xhr = new XMLHttpRequest()
      xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
          console.log(JSON.parse(xhr.responseText))
        }
      }
      xhr.open('get', 'https://restapi.amap.com/v3/weather/weatherInfo?key=高德key&extensions=base&city=济南市', true)
      xhr.send()
    </script> -->

    <!-- 和风天气查询 -->
    <!-- <script>
      var xhr = new XMLHttpRequest()
      xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
          console.log(JSON.parse(xhr.responseText))
        }
      }
      // location需要传经纬度 例如: 济南市117.116279,36.662589
      xhr.open('get', 'https://devapi.qweather.com/v7/weather/now?location=117.116279,36.662589&key=和风天气key', true)
      xhr.send()
    </script> -->
  </body>
</html>
